package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author atguigu-mqx
 * @Description TODO
 * @Date 2023/8/22 11:50
 * @Version 1.0
 */
@RestController
@RequestMapping("admin/product/test")
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping("testLock")
    public Result testLock(){
        //  调用服务层方法
        try {
            this.testService.testLock();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        //  返回数据
        return Result.ok();
    }

    /**
     * 读锁
     * @return
     */
    @GetMapping("readLock")
    public Result readLock(){
        String msg = this.testService.readLock();
        return Result.ok(msg);
    }
    /**
     * 写锁
     * @return
     */
    @GetMapping("writeLock")
    public Result writeLock(){
        String msg = this.testService.writeLock();
        return Result.ok(msg);
    }

}
